<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Banner;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class BannerController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid(): Grid
    {
        return Grid::make(new Banner(), function (Grid $grid) {
            $grid->column('id');
            $grid->column('title');
            $grid->column('image')->image(aliyun_domain(), 100, 100);
            $grid->column('locale')->display(function ($var){
                return implode(',', $var);
            });
            $grid->column('show')->switch();
            $grid->column('sort');

            $grid->disableRowSelector();
            $grid->disableViewButton();
            $grid->showQuickEditButton();
            $grid->disableFilterButton();
        });
    }


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form(): Form
    {
        return Form::make(new Banner(), function (Form $form) {
            $form->display('id');
            $form->multipleSelect('locale')->options(config('app.locale_list'))->required();
            $form->text('title')->required();
            $form->image('image',)->uniqueName()->required();
            $form->switch('show')->default(false);
            $form->number('sort')->default(0)->max(100);
        });
    }
}
